from random import *
# for i in range(1, 10+1, 2):
#     print(i, end=" ")
#
# # 打印100以内能被3整除

for i in range(1, 100+1):
    if i % 3 == 0:
        print(i, end=" ")


# 猜数字
num = randint(1, 10)

while True:
    guess = int(input("请输入一个数字："))
    if guess < num:
        print("猜小了")
    elif guess > num:
        print("猜大了")
    else:
        print("猜对了")
        break

for i in range(1, 100+1):
    # if i % 7 == 0 or str(i).find("7") != -1:
    # if i % 7 == 0 or str(i).cout("7")> 0:
    if i % 7 == 0 or '7' in str(i) != -1:
        print(i, end=" ")



# # 打印菱形式
for i in range(1, 11+1, 2):
    print(("*" * i).center(11))
for i in range(9, 0, -2):
    print(("*" * i).center(11))

# 菱形 多层嵌套
rows = 10
row = 1
while row < rows:
    print(" " * (rows - row), end="")
    print("*" * (2 * row - 1), end="\n")
    row += 1
row-= 2
while row > 0:
   print(" " * (rows - row), end="")
   print("*" * (2 * row - 1), end="\n")
   row -= 1


# 水仙花数
for i in range(1, 1000+1):
    sum=0
    length=len(str(i))
    for j in range(1, length+1):
        sum += int(str(i)[j-1]) ** length
    if sum == i:
        print(i, end=" ")




# 100 以内的质数
flag=True
for i in range(2, 100+1):
    for j in range(2, i):
        if i % j == 0:
            flag = False
            break
        else:
            flag = True
    if flag == True:
         print(i,end=" ")
# 100 以内的完数
for i in range(1, 100+1):
    sum = 0
    for j in range(1, i):
        if i % j == 0:
            sum += j
    if sum == i:
        print(i, end=" ")

# 斐波那契
for i in range(0, 10):
    if i == 0:
        print(0, end=" ")

    elif i == 1:
        print(1, end=" ")
    else:
        a, b = 0, 1
        for _ in range(2, i+1):
         a, b = b, a+b

        print (b, end=" ")
# 99 乘法表
for i in range(1, 10):
    for j in range (1, i+1):
        print("%d * %d = %d" % (j, i, i*j), end="\t")
    print("\n")
